import 'package:flutter/material.dart';
import 'package:shopping_group/base/base_constant.dart';
import 'package:shopping_group/entity/lz_text.dart';
import 'package:shopping_group/http/apis/apis.dart';
import 'package:shopping_group/http/http_request_all.dart';
import 'package:shopping_group/modle/person/account/widget/lz_mine_accoun_money_widget.dart';
import 'package:shopping_group/res/colors.dart';
import 'package:shopping_group/res/dimens.dart';
import 'package:shopping_group/utils/widget_utils.dart';
import 'package:bot_toast/bot_toast.dart';

enum LzAccountStyle {
  myJintie, //我的津贴
  myZt, //直推
  myDsFuli, //福利金
  myAdverRights, //看广告权益
  myDJQ, //代金券
  myProductShelf, //商品上架权益
  myTeamJT //团队津贴

}

class LzMineAccountDetailPage extends StatefulWidget {
  final LzAccountStyle accountStyle;

  LzMineAccountDetailPage({Key key, this.accountStyle}) : super(key: key);

  @override
  _LzMineAccountDetailPageState createState() => _LzMineAccountDetailPageState();
}

class _LzMineAccountDetailPageState extends State<LzMineAccountDetailPage> {
  String title = "";
  String accountTitle = "";
  String url = "";
  final Map<String, dynamic> resultMap = {};

  String _titleCount = "";
  String _leftCount = "";
  String _rightCount = "";

  @override
  void initState() {
    super.initState();

    switch (widget.accountStyle) {
      case LzAccountStyle.myJintie:
        title = "津贴账户";
        accountTitle = "津贴余额";
        url = Apis.JIN_TIE_SUM;
        break;
      case LzAccountStyle.myZt:
        title = "直推奖账户";
        accountTitle = "直推奖金额";
        url = Apis.ZI_TUI_SUM;

        break;
      case LzAccountStyle.myDsFuli:
        title = "电商福利金";
        accountTitle = "电商福利金余额";
        url = Apis.DS_FULI_SUM;

        break;
      case LzAccountStyle.myAdverRights:
        title = "看广告权益账户";
        accountTitle = "剩余次数";
        url = Apis.GUAN_GAOCT_INFO;

        break;
      case LzAccountStyle.myDJQ:
        title = "代金券账户";
        accountTitle = "代金券余额";
        url = Apis.GET_DJQ_SUM;

        break;
      case LzAccountStyle.myProductShelf:
        title = "商品上架权益账户";
        accountTitle = "商品上架权益剩余数";
        url = Apis.GET_CANUP_MY_COMMO_SUM;

        break;
      case LzAccountStyle.myTeamJT:
        title = "团队津贴盈余账户";
        accountTitle = "团队津贴盈余";
        url = Apis.GET_GROUP_JT_SUM;

        break;

      default:
    }

/**
 * allGET 总获取
 * allPay 总消费
 * nowVal 总余额
 */
    //这里偷个懒, 直接请求了
    BotToast.showLoading();
    HttpUtilAll.post(url, data: {"val": BaseConstant.userId}, success: (result) {
      BotToast.closeAllLoading();
      if (null != result) {
        resultMap.addAll(result);

        switch (widget.accountStyle) {
          case LzAccountStyle.myAdverRights:
            _titleCount = result["dsGgNoDoCt"] ?? "";
            _leftCount = "总共获取次数\n" + result["dsGgAllCt"] ?? "";
            _rightCount = "总共使用次数\n" + result["dsGgHadDoCt"] ?? "";

            break;
          case LzAccountStyle.myProductShelf:
          case LzAccountStyle.myTeamJT:
            _titleCount = result["nowVal"] ?? "";
            _leftCount = "总共获取次数\n" + result["allGet"] ?? "";
            _rightCount = "总共使用次数\n" + result["allPay"] ?? "";

            break;
          default:
            _titleCount = result["nowVal"] ?? "";
            _leftCount = "总共领取\n" + result["allGet"] ?? "";
            _rightCount = "总共消费\n" + result["allPay"] ?? "";
        }

        setState(() {});
      }
    }, error: (errorMsg) {
      BotToast.closeAllLoading();
      // 请求失败返回的错误信息
      BotToast.showText(text: errorMsg);
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: WidgetUtils.showAppar(context, title,
          textColor: Colors.white, isHide: false, backgroundColor: Colours.blackground_609),
      body: SafeArea(
        child: Container(
          decoration: BoxDecoration(
            color: Colours.title_white,
          ),
          child: Column(
            mainAxisAlignment: MainAxisAlignment.start,
            crossAxisAlignment: CrossAxisAlignment.center,
            children: <Widget>[
              Expanded(
                  flex: 1,
                  child: Container(
                    decoration: BoxDecoration(
                      color: Colours.blackground_609,
                    ),
                    child: Stack(children: <Widget>[
                      Container(
                          alignment: Alignment.centerLeft,
                          padding: EdgeInsets.symmetric(horizontal: 16, vertical: 4),
                          child: Column(crossAxisAlignment: CrossAxisAlignment.start, children: [
                            Expanded(
                                child: Column(mainAxisAlignment: MainAxisAlignment.start, children: <Widget>[
                              Container(
                                alignment: Alignment.centerLeft,
                                child: LzText(accountTitle, fontSize: 14),
                              ),
                              Expanded(
                                child: Container(
                                  alignment: Alignment.center,
                                  child: LzText(_titleCount, fontSize: 30),
                                ),
                              ),
                              Row(
                                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                                crossAxisAlignment: CrossAxisAlignment.start,
                                children: <Widget>[
                                  Column(
                                    mainAxisAlignment: MainAxisAlignment.start,
                                    crossAxisAlignment: CrossAxisAlignment.start,
                                    children: <Widget>[
                                      WidgetUtils.getTextColorView(_leftCount, Colours.title_white, Dimens.FONT_SIZE_14,
                                          textAlign: TextAlign.start),
                                    ],
                                  ),
                                  Column(
                                    mainAxisAlignment: MainAxisAlignment.start,
                                    crossAxisAlignment: CrossAxisAlignment.start,
                                    children: <Widget>[
                                      WidgetUtils.getTextColorView(
                                          _rightCount, Colours.title_white, Dimens.FONT_SIZE_14,
                                          textAlign: TextAlign.end),
                                    ],
                                  ),
                                ],
                              ),
                            ]))
                          ]))
                    ]),
                  )),
              SizedBox(
                height: 8,
              ),
              Expanded(
                child: Container(
                    color: Colours.transparent,
                    padding: EdgeInsets.symmetric(horizontal: 16, vertical: 8),
                    child: Flex(
                      direction: Axis.vertical,
                      children: <Widget>[
                        Expanded(
                          child: LzMineAccountMoneyWidget(accountStyle: widget.accountStyle),
                        ),
                      ],
                    )),
                flex: 3,
              ),
              SizedBox(
                height: 8,
              ),
            ],
          ),
        ),
      ),
    );
  }
}
